<?php

namespace App\Services\User;

use \App\Services\User\Department\DepartmentLogic;
/**
 * 部门管理的逻辑层
 */
class Department
{
    // 按分页获取部门列表
    public function list(array $data): array
    {
        $data = init_array($data,['page' => 1, 'list_rows' => '', 'status' => '']);

        return (new DepartmentLogic())->list($data);
    }
    // 增加一条部门记录
    public function add(array $data): array
    {
        $data = init_array($data,['name' => ' ', 'name_cn' => ' ', 'weight' => '0']);

        ValidateRole::checkValidate($data,['name','weight','name_cn']);
        return (new DepartmentLogic())->add($data);
    }
    // 获取某个部门的详情
    public function getDepartmentInfo($data): array
    {
        $data = init_array($data,['id'=>0]);

        return (new DepartmentLogic())->getDepartmentInfo($data);
    }
    // 编辑用户部门名,权重,和附加菜单信息
    public function edit(array $data): array
    {

        if(!isset($data['name']) && !isset($data['name_cn'])&& isset($data['weight']) && isset($data['menu']))
        {
            return verify_err($data, 'name,name_cn,weight和menu四个参数至少要传一个');
        }
        $data = init_array($data,['id'=>0]);

        ValidateRole::checkValidate($data,['id', 'name', 'name_cn', 'weight', 'menu']);
        return (new DepartmentLogic())->edit($data);
    }
    // 启用一个部门
    public function start(array $data): array
    {
        ValidateRole::checkValidate($data,['id','name']);
        return (new DepartmentLogic())->start($data);
    }
    // 禁用一个部门
    public function stop(array $data): array
    {
        ValidateRole::checkValidate($data,['id','name']);
        return (new DepartmentLogic())->stop($data);
    }

}
